package com.shu.task;

import com.shu.pojo.Article;
import com.shu.service.ArticleService;
import com.shu.utils.CrawlerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @author shu
 * @date 2021/3/23
 */

@Service
public class TimingService {

    @Autowired
    ArticleService articleService;

    /**
     * 政务公开定时任务
     */
    //表示每个星期三中午12点
    @Scheduled(cron = "0 0 12 ? * WED")
    public void Write_Government(){
        try {
            List<Article> list = CrawlerUtils.Government_Crawler();
            articleService.saveBatch(list);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 营商定时任务
     */
    //每天中午12点触发
    @Scheduled(cron = "0 0 12 * * ?")
    public void Write_Business(){
        try {
            List<Article> list = CrawlerUtils.Business_Crawler();
            articleService.saveBatch(list);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 法规定时任务
     */
    //每天上午10:15触发
    @Scheduled(cron = "0 15 10 ? * *")
    public void Write_Laws(){
        try {
            List<Article> list = CrawlerUtils.Laws_Crawler();
            articleService.saveBatch(list);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 产业定时任务
     */
    //每月最后一日的上午10:15触发
    @Scheduled(cron = "0 15 10 L * ?")
    public void Write_Industry(){
        try {
            List<Article> list = CrawlerUtils.Industry_Crawler();
            articleService.saveBatch(list);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 要闻定时任务
     */
    //2021 每天10:15
    @Scheduled(cron = "0 15 10 L * ?")
    public void Write_News(){
        try {
            List<Article> list = CrawlerUtils.News_Crawler();
            articleService.saveBatch(list);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




}
